//
// Created by 11510 on 2024/6/18.
//

#include "Figure.h"
#include <cmath>

class Rectangle : public Figure {
public:
    Rectangle(double len, double wid)
            : _length(len), _width(wid) {}

    string getName() const override {
        return "矩形";
    }

    double getArea() const override {
        return _length * _width;
    }

private:
    double _length;
    double _width;
};

class Circle : public Figure {
public:
    Circle(double r) : _radius(r) {}

    string getName() const override {
        return "圆形";
    }

    double getArea() const override {
        return PI * _radius * _radius;
    }

private:
    double _radius;
    /**
     * double 需要在运行时确定值，需要constexpr
     */
    static constexpr double PI = 3.1415926535;
};

class Triangle : public Figure {
public:
    Triangle(double a, double b, double c)
            : _a(a), _b(b), _c(c) {}

    string getName() const override {
        return "三角形";
    }

    double getArea() const override {
        double p = (_a + _b + _c) / 2;
        return sqrt(p * (p - _a) * (p - _b) * (p - _c));
    }

private:
    double _a, _b, _c;
};


void test() {
    Rectangle r(10, 20);
    Circle c(15);
    Triangle t(3, 4, 5);
    display(r);
    display(c);
    display(t);
}

int main(void){
    test();
    return 0;
}